<?php
include 'config/koneksi.php';
include 'config/fungsi_thumb.php';
include "config/library.php";
include "config/fungsi_seo.php";


if($_POST['action']=='ubahavatar'){
$fupload = $_POST['fupload'];
$username = $_POST['username'];
//validasi avatar
if(!preg_match('/^(([a-zA-Z0-9\-])+\.)+(jpg)+$/',$fupload)){
echo '<font color="red">Tipe file harus .jpg atau .jpeg</font>';
exit();
}
if(!preg_match('/^(([a-zA-Z0-9\-])+\.)+(jpeg)+$/',$fupload)){
echo '<font color="red">Tipe file harus .jpg atau .jpeg</font>';
exit();
}
if(!preg_match('/^(([a-zA-Z0-9\-])+\.)+(JPG)+$/',$fupload)){
echo '<font color="red">Tipe file harus .jpg atau .jpeg</font>';
exit();
}
if(!preg_match('/^(([a-zA-Z0-9\-])+\.)+(JPEG)+$/',$fupload)){
echo '<font color="red">Tipe file harus .jpg atau .jpeg</font>';
exit();
}
//saving data
$query="UPDATE users SET avatar='$fupload' WHERE username='$username'";
$hasil=@mysql_query($query);
if($hasil){
	echo '<font color="green">DATA HAS BEEN SAVED </font><br>';
}else {
	echo '<font color="red">Error, TIDAK BISA KONEK KE BASIS DATA</font>';
}
echo "<a href=media.php?module=profiluser>Kembali ke Profil</a>"; 
}

if($_POST['action']=='ubahemail'){
$email = $_POST['email'];
$username = $_POST['username'];
//validasi email
if(!preg_match('/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/',$email)){
echo 'Ivalid Email Address'; exit();
}
//saving data
$query="UPDATE users SET email='$email' WHERE username='$username'";
$hasil=@mysql_query($query);
if($hasil){
	echo '<font color="green">DATA HAS BEEN SAVED </font><br>';
}else {
	echo '<font color="red">Error, TIDAK BISA KONEK KE BASIS DATA</font>';
}
echo "<a href=media.php?module=profiluser>Kembali ke Profil</a>"; 
}

if($_POST['action']=='ubahabout'){
$about = $_POST['about'];
$username = $_POST['username'];

//saving data
$query="UPDATE users SET about='$about' WHERE username='$username'";
$hasil=@mysql_query($query);
if($hasil){
	echo '<font color="green">DATA HAS BEEN SAVED </font><br>';
}else {
	echo '<font color="red">Error, TIDAK BISA KONEK KE BASIS DATA</font>';
}
echo "<a href=media.php?module=profiluser>Kembali ke Profil</a>"; 
}

if($_POST['action']=='hapuskomentar'){
$id_komentar = $_POST['id_komentar'];
$id_berita = $_POST['id_berita'];

//saving data
$query="DELETE FROM komentar WHERE id_komentar='$id_komentar'";
$hasil=@mysql_query($query);
if($hasil){
	echo '<font color="green">DATA HAS BEEN SAVED </font><br>';
}else {
	echo '<font color="red">Error, TIDAK BISA KONEK KE BASIS DATA</font>';
}
//echo "<meta http-equiv='refresh' content='0; url=media.php?module=profiluser'>";
//echo "<a href=media.php?module=detailberita&id=$id_berita>Kembali ke Profil</a>"; 
}

if($_POST['action']=='like'){
$id_berita = $_POST['id_berita'];
$username = $_POST['username'];
//saving data
$query="INSERT INTO likes (id_berita, username) VALUES ('$id_berita','$username')";
$hasil=@mysql_query($query);
if($hasil){
	echo '<font color="green">DATA HAS BEEN SAVED </font><br>';
}else {
	echo '<font color="red">Error, TIDAK BISA KONEK KE BASIS DATA</font>';
}
//echo "<meta http-equiv='refresh' content='0; url=media.php?module=profiluser'>";
//echo "<a href=media.php?module=detailberita&id=$id_berita>Kembali ke Profil</a>"; 
}
?>